<?php

class inventoryActions extends sfActions {

    public function preExecute() {
        date_default_timezone_set(AppTools::TIMEZONE);
    }

    public function executeDaily(sfWebRequest $request) {
        $date = $request->getParameter('date', date('Y-m-d'));
        $storeId = $request->getParameter('store_id', $this->getUser()->getStoreId());
        $categoryId = $request->getParameter('category_id', 0);
        $productId = $request->getParameter('product_id', 0);
        $stores = StoreTable::getForSelect();
        $categories = CategoryTable::getForSelect();

        $rows = InventoryTable::getListDaily($date, $storeId, $categoryId, $productId);

        $this->rows = $rows;
        $this->date = $date;
        $this->stores = $stores;
        $this->storeId = $storeId;
        $this->categories = $categories;
        $this->categoryId = $categoryId;
        $this->productId = $productId;
        $this->urlProduct = AppTools::getFullUrl() . '/ajax/product';
    }

    public function executeDetailed(sfWebRequest $request) {
        $dateBegin = $request->getParameter('dateBegin', date('Y-m-d'));
        $dateEnd = $request->getParameter('dateEnd', date('Y-m-d'));
        $storeId = $request->getParameter('store_id', 0);
        $categoryId = $request->getParameter('category_id', 0);
        $productId = $request->getParameter('product_id', 0);
        $stores = StoreTable::getForSelect();
        $categories = CategoryTable::getForSelect();

        $rows = InventoryTable::getList($dateBegin, $dateEnd, $storeId, $categoryId, $productId);

        $this->rows = $rows;
        $this->dateBegin = $dateBegin;
        $this->dateEnd = $dateEnd;
        $this->stores = $stores;
        $this->storeId = $storeId;
        $this->categories = $categories;
        $this->categoryId = $categoryId;
        $this->productId = $productId;
        $this->urlProduct = AppTools::getFullUrl() . '/ajax/product';
    }

}
